<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>故障处理流程</title>
  <link href="css/layui.css" rel="stylesheet" type="text/css" />
  <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
            <div class="layui-card-header">
                <p class="title-row"> 故障处理流程</p>
                <p class="layadmin-font-em">应急故障点<span class="fault-point-name" style="margin-left: 20px; color: burlywood;"></span></p>
              </div>
            <div class="layui-card-body">
                <form class="layui-form" action="">
                  <div class="layui-form-item proBox">
                    <h3 class="title-row">专业状态选择</h3>
                    <div style="color: #fff; text-align: center; margin:30px 0;" >
                      <input type="checkbox" name="state_9" title="供电" lay-filter="cOne" class="cOne">
                      <input type="checkbox" name="state_10" title="车辆" lay-filter="cOne" class="cOne">
                      <input type="checkbox" name="state_11" title="通号" lay-filter="cOne" class="cOne">
                      <input type="checkbox" name="state_12" title="工务" lay-filter="cOne" class="cOne">
                      <input type="checkbox" name="state_13" title="物后" lay-filter="cOne" class="cOne">
                    </div>
                  </div>
                </form>
                <div class="maintenance">
                    <h3 class="title-row">维保总体处理流程</h3>
                    <form class="layui-form" action="">
                        <div class="layui-form-item layui-form-text textBox">
                            <textarea name="desc" placeholder="请输入故障现象" class="layui-textarea"></textarea>
                        </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block sumitBtn">
                                <button class="layui-btn confirmButton" lay-submit lay-filter="formDemo" type="button">确认</button>
                                <button type="reset" class="layui-btn layui-btn-primary closePage" type="button">取消</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="fakeTable" style="display: none;">
              <table class="layui-hide" id="fakeTable" lay-filter="fakeTable"></table>
            </div>
        </div>
    </div>
  </div>
  <script src="../static/layui.js"></script>
  <script src="/json/table.js"></script>
  <script>

    var num = 4;
    //一般直接写在一个js文件中
    layui.use(['layer', 'form', 'table'], function () {
      var layer = layui.layer
        , $ = layui.$
        , table = layui.table //表格
        , form = layui.form;

        var flowData = window.parent.getTableRow();
        $('.fault-point-name').text(flowData.faultID);
        
        $('.closePage').on('click', function () {
          closeSonPage();
        });
        
        $('.confirmButton').on('click', function (data) {

          var faultDesc = $("[name='desc']").val();
          if(faultDesc.length<1){
            alertMsg('故障现象必须填写');
            return;
          }
          
          if($(".cOne:checked").length<1){
            alertMsg('请选择专业');
            return;
          }
          var ids=[];
          var check = $(".cOne:checked");
          for(var i=0;i<check.length;i++){
            var checkName=check[i].name;
            ids[i]=checkName.replace('state_','');
          }
          table.render({
                    elem: '#fakeTable'
                    , url: '/flowLink/addFaultFlowLink'
                    , where: { 'faultId': flowData.faultID,
                      'faultContent':faultDesc,
                      'flowLinkIds': ids
                    }
                    , parseData: function (res) {
                      layer.open({
                        type: 1
                        ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        ,id: 'layerDemoauto' //防止重复弹出
                        ,content: '<div style="padding: 20px 100px;">'+ res.msg +'</div>'
                        ,btn: '关闭'
                        ,btnAlign: 'c' //按钮居中
                        ,shade: 0 //不显示遮罩
                        ,yes: function(){
                          // layer.close(layer.index);
                          if(res.code=='success'){
                            window.parent.refreshAddFormData();
                            layer.closeAll(); 
                            closeSonPage();
                          }else{
                            layer.closeAll('page'); 
                          }
                          
                        }
                      });

                        return {
                            "code": res.code,
                            "msg": res.msg
                        };
                    }
                    , cols: [[
                    ]]
                });
                
        });
        function closeSonPage(){
          var index = parent.layer.getFrameIndex(window.name);
          parent.layer.close(index);//关闭当前页
        }
        function alertMsg(msg){
          layer.open({
              type: 1
              ,offset: 'auto' //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
              ,id: 'layerDemoauto' //防止重复弹出
              ,content: '<div style="padding: 20px 100px;">'+ msg +'</div>'
              ,btn: '关闭'
              ,btnAlign: 'c' //按钮居中
              ,shade: 0 //不显示遮罩
              ,yes: function(){
                // layer.close(layer.index);
                layer.closeAll('page'); 
              }
            });
        }
    });

   
    

   

  </script>
</body>

</html>